package org.xwalk.core.internal;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.ValueCallback;
import android.widget.EditText;
import android.widget.FrameLayout;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class XWalkUIClientBridge extends XWalkUIClientInternal {
    private XWalkCoreBridge coreBridge;
    private Object wrapper;

    public Object getWrapper() {
        return wrapper;
    }

    private ReflectMethod enumJavascriptMessageTypeClassValueOfMethod = new ReflectMethod();

    private Object ConvertJavascriptMessageTypeInternal(JavascriptMessageTypeInternal type) {
        return enumJavascriptMessageTypeClassValueOfMethod.invoke(type.toString());
    }

    private ReflectMethod enumConsoleMessageTypeClassValueOfMethod = new ReflectMethod();

    private Object ConvertConsoleMessageType(ConsoleMessageType type) {
        return enumConsoleMessageTypeClassValueOfMethod.invoke(type.toString());
    }

    private ReflectMethod enumInitiateByClassValueOfMethod = new ReflectMethod();

    private Object ConvertInitiateByInternal(InitiateByInternal type) {
        return enumInitiateByClassValueOfMethod.invoke(type.toString());
    }

    private ReflectMethod enumLoadStatusClassValueOfMethod = new ReflectMethod();

    private Object ConvertLoadStatusInternal(LoadStatusInternal type) {
        return enumLoadStatusClassValueOfMethod.invoke(type.toString());
    }



    public XWalkUIClientBridge(XWalkViewBridge view, Object wrapper) {
        super(view);

        this.wrapper = wrapper;
        reflectionInit();

    }

        @Override
    public boolean onCreateWindowRequested(XWalkViewInternal view, InitiateByInternal initiator, ValueCallback<XWalkViewInternal> callback) {
        if ((view instanceof XWalkViewBridge)) {
            return onCreateWindowRequested((XWalkViewBridge) view, initiator, callback);
        } else {
            return super.onCreateWindowRequested(view, initiator, callback);
        }
    }

    public boolean onCreateWindowRequested(XWalkViewBridge view, InitiateByInternal initiator, ValueCallback<XWalkViewInternal> callback) {
        if (onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod == null || onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod.isNull()) {
            return onCreateWindowRequestedSuper(view, initiator, callback);
        } else {
            final ValueCallback<XWalkViewInternal> callbackFinal = callback;
            return (Boolean)onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), ConvertInitiateByInternal(initiator), new ValueCallback<Object>() {
                @Override
                public void onReceiveValue(Object value) {
                    callbackFinal.onReceiveValue((XWalkViewBridge) coreBridge.getBridgeObject(value));
                }
            });
        }
    }

    public boolean onCreateWindowRequestedSuper(XWalkViewBridge view, InitiateByInternal initiator, ValueCallback<XWalkViewInternal> callback) {
        boolean ret;
        ret = super.onCreateWindowRequested(view, initiator, callback);
        
        return ret;
    }

    private ReflectMethod onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod = new ReflectMethod(null, "onCreateWindowRequested");

    @Override
    public void onIconAvailable(XWalkViewInternal view, String url, Message startDownload) {
        if ((view instanceof XWalkViewBridge)) {
            onIconAvailable((XWalkViewBridge) view, url, startDownload);
        } else {
            super.onIconAvailable(view, url, startDownload);
        }
    }

    public void onIconAvailable(XWalkViewBridge view, String url, Message startDownload) {
        if (onIconAvailableXWalkViewInternalStringMessageMethod == null || onIconAvailableXWalkViewInternalStringMessageMethod.isNull()) {
            onIconAvailableSuper(view, url, startDownload);
        } else {
            onIconAvailableXWalkViewInternalStringMessageMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url, startDownload);
        }
    }

    public void onIconAvailableSuper(XWalkViewBridge view, String url, Message startDownload) {
        super.onIconAvailable(view, url, startDownload);
    }

    private ReflectMethod onIconAvailableXWalkViewInternalStringMessageMethod = new ReflectMethod(null, "onIconAvailable");

    @Override
    public void onReceivedIcon(XWalkViewInternal view, String url, Bitmap icon) {
        if ((view instanceof XWalkViewBridge)) {
            onReceivedIcon((XWalkViewBridge) view, url, icon);
        } else {
            super.onReceivedIcon(view, url, icon);
        }
    }

    public void onReceivedIcon(XWalkViewBridge view, String url, Bitmap icon) {
        if (onReceivedIconXWalkViewInternalStringBitmapMethod == null || onReceivedIconXWalkViewInternalStringBitmapMethod.isNull()) {
            onReceivedIconSuper(view, url, icon);
        } else {
            onReceivedIconXWalkViewInternalStringBitmapMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url, icon);
        }
    }

    public void onReceivedIconSuper(XWalkViewBridge view, String url, Bitmap icon) {
        super.onReceivedIcon(view, url, icon);
    }

    private ReflectMethod onReceivedIconXWalkViewInternalStringBitmapMethod = new ReflectMethod(null, "onReceivedIcon");

    @Override
    public void onRequestFocus(XWalkViewInternal view) {
        if ((view instanceof XWalkViewBridge)) {
            onRequestFocus((XWalkViewBridge) view);
        } else {
            super.onRequestFocus(view);
        }
    }

    public void onRequestFocus(XWalkViewBridge view) {
        if (onRequestFocusXWalkViewInternalMethod == null || onRequestFocusXWalkViewInternalMethod.isNull()) {
            onRequestFocusSuper(view);
        } else {
            onRequestFocusXWalkViewInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper());
        }
    }

    public void onRequestFocusSuper(XWalkViewBridge view) {
        super.onRequestFocus(view);
    }

    private ReflectMethod onRequestFocusXWalkViewInternalMethod = new ReflectMethod(null, "onRequestFocus");

    @Override
    public void onJavascriptCloseWindow(XWalkViewInternal view) {
        if ((view instanceof XWalkViewBridge)) {
            onJavascriptCloseWindow((XWalkViewBridge) view);
        } else {
            super.onJavascriptCloseWindow(view);
        }
    }

    public void onJavascriptCloseWindow(XWalkViewBridge view) {
        if (onJavascriptCloseWindowXWalkViewInternalMethod == null || onJavascriptCloseWindowXWalkViewInternalMethod.isNull()) {
            onJavascriptCloseWindowSuper(view);
        } else {
            onJavascriptCloseWindowXWalkViewInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper());
        }
    }

    public void onJavascriptCloseWindowSuper(XWalkViewBridge view) {
        super.onJavascriptCloseWindow(view);
    }

    private ReflectMethod onJavascriptCloseWindowXWalkViewInternalMethod = new ReflectMethod(null, "onJavascriptCloseWindow");

    @Override
    public boolean onJavascriptModalDialog(XWalkViewInternal view, JavascriptMessageTypeInternal type, String url, String message, String defaultValue, XWalkJavascriptResultInternal result) {
        if ((view instanceof XWalkViewBridge)) {
            return onJavascriptModalDialog((XWalkViewBridge) view, type, url, message, defaultValue, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)));
        } else {
            return super.onJavascriptModalDialog(view, type, url, message, defaultValue, result);
        }
    }

    public boolean onJavascriptModalDialog(XWalkViewBridge view, JavascriptMessageTypeInternal type, String url, String message, String defaultValue, XWalkJavascriptResultHandlerBridge result) {
        if (onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod == null || onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod.isNull()) {
            return onJavascriptModalDialogSuper(view, type, url, message, defaultValue, result);
        } else {
            return (Boolean)onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), ConvertJavascriptMessageTypeInternal(type), url, message, defaultValue, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)).getWrapper());
        }
    }

    public boolean onJavascriptModalDialogSuper(XWalkViewBridge view, JavascriptMessageTypeInternal type, String url, String message, String defaultValue, XWalkJavascriptResultHandlerBridge result) {
        boolean ret;
        ret = super.onJavascriptModalDialog(view, type, url, message, defaultValue, result);
        
        return ret;
    }

    private ReflectMethod onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJavascriptModalDialog");

    @Override
    public void onFullscreenToggled(XWalkViewInternal view, boolean enterFullscreen) {
        if ((view instanceof XWalkViewBridge)) {
            onFullscreenToggled((XWalkViewBridge) view, enterFullscreen);
        } else {
            super.onFullscreenToggled(view, enterFullscreen);
        }
    }

    public void onFullscreenToggled(XWalkViewBridge view, boolean enterFullscreen) {
        if (onFullscreenToggledXWalkViewInternalbooleanMethod == null || onFullscreenToggledXWalkViewInternalbooleanMethod.isNull()) {
            onFullscreenToggledSuper(view, enterFullscreen);
        } else {
            onFullscreenToggledXWalkViewInternalbooleanMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), enterFullscreen);
        }
    }

    public void onFullscreenToggledSuper(XWalkViewBridge view, boolean enterFullscreen) {
        super.onFullscreenToggled(view, enterFullscreen);
    }

    private ReflectMethod onFullscreenToggledXWalkViewInternalbooleanMethod = new ReflectMethod(null, "onFullscreenToggled");

    @Override
    public void openFileChooser(XWalkViewInternal view, ValueCallback<Uri> uploadFile, String acceptType, String capture) {
        if ((view instanceof XWalkViewBridge)) {
            openFileChooser((XWalkViewBridge) view, uploadFile, acceptType, capture);
        } else {
            super.openFileChooser(view, uploadFile, acceptType, capture);
        }
    }

    public void openFileChooser(XWalkViewBridge view, ValueCallback<Uri> uploadFile, String acceptType, String capture) {
        if (openFileChooserXWalkViewInternalValueCallbackStringStringMethod == null || openFileChooserXWalkViewInternalValueCallbackStringStringMethod.isNull()) {
            openFileChooserSuper(view, uploadFile, acceptType, capture);
        } else {
            openFileChooserXWalkViewInternalValueCallbackStringStringMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), uploadFile, acceptType, capture);
        }
    }

    public void openFileChooserSuper(XWalkViewBridge view, ValueCallback<Uri> uploadFile, String acceptType, String capture) {
        super.openFileChooser(view, uploadFile, acceptType, capture);
    }

    private ReflectMethod openFileChooserXWalkViewInternalValueCallbackStringStringMethod = new ReflectMethod(null, "openFileChooser");

    @Override
    public void onScaleChanged(XWalkViewInternal view, float oldScale, float newScale) {
        if ((view instanceof XWalkViewBridge)) {
            onScaleChanged((XWalkViewBridge) view, oldScale, newScale);
        } else {
            super.onScaleChanged(view, oldScale, newScale);
        }
    }

    public void onScaleChanged(XWalkViewBridge view, float oldScale, float newScale) {
        if (onScaleChangedXWalkViewInternalfloatfloatMethod == null || onScaleChangedXWalkViewInternalfloatfloatMethod.isNull()) {
            onScaleChangedSuper(view, oldScale, newScale);
        } else {
            onScaleChangedXWalkViewInternalfloatfloatMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), oldScale, newScale);
        }
    }

    public void onScaleChangedSuper(XWalkViewBridge view, float oldScale, float newScale) {
        super.onScaleChanged(view, oldScale, newScale);
    }

    private ReflectMethod onScaleChangedXWalkViewInternalfloatfloatMethod = new ReflectMethod(null, "onScaleChanged");

    @Override
    public boolean shouldOverrideKeyEvent(XWalkViewInternal view, KeyEvent event) {
        if ((view instanceof XWalkViewBridge)) {
            return shouldOverrideKeyEvent((XWalkViewBridge) view, event);
        } else {
            return super.shouldOverrideKeyEvent(view, event);
        }
    }

    public boolean shouldOverrideKeyEvent(XWalkViewBridge view, KeyEvent event) {
        if (shouldOverrideKeyEventXWalkViewInternalKeyEventMethod == null || shouldOverrideKeyEventXWalkViewInternalKeyEventMethod.isNull()) {
            return shouldOverrideKeyEventSuper(view, event);
        } else {
            return (Boolean)shouldOverrideKeyEventXWalkViewInternalKeyEventMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), event);
        }
    }

    public boolean shouldOverrideKeyEventSuper(XWalkViewBridge view, KeyEvent event) {
        boolean ret;
        ret = super.shouldOverrideKeyEvent(view, event);
        
        return ret;
    }

    private ReflectMethod shouldOverrideKeyEventXWalkViewInternalKeyEventMethod = new ReflectMethod(null, "shouldOverrideKeyEvent");

    @Override
    public void onUnhandledKeyEvent(XWalkViewInternal view, KeyEvent event) {
        if ((view instanceof XWalkViewBridge)) {
            onUnhandledKeyEvent((XWalkViewBridge) view, event);
        } else {
            super.onUnhandledKeyEvent(view, event);
        }
    }

    public void onUnhandledKeyEvent(XWalkViewBridge view, KeyEvent event) {
        if (onUnhandledKeyEventXWalkViewInternalKeyEventMethod == null || onUnhandledKeyEventXWalkViewInternalKeyEventMethod.isNull()) {
            onUnhandledKeyEventSuper(view, event);
        } else {
            onUnhandledKeyEventXWalkViewInternalKeyEventMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), event);
        }
    }

    public void onUnhandledKeyEventSuper(XWalkViewBridge view, KeyEvent event) {
        super.onUnhandledKeyEvent(view, event);
    }

    private ReflectMethod onUnhandledKeyEventXWalkViewInternalKeyEventMethod = new ReflectMethod(null, "onUnhandledKeyEvent");

    @Override
    public boolean onConsoleMessage(XWalkViewInternal view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
        if ((view instanceof XWalkViewBridge)) {
            return onConsoleMessage((XWalkViewBridge) view, message, lineNumber, sourceId, messageType);
        } else {
            return super.onConsoleMessage(view, message, lineNumber, sourceId, messageType);
        }
    }

    public boolean onConsoleMessage(XWalkViewBridge view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
        if (onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod == null || onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod.isNull()) {
            return onConsoleMessageSuper(view, message, lineNumber, sourceId, messageType);
        } else {
            return (Boolean)onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), message, lineNumber, sourceId, ConvertConsoleMessageType(messageType));
        }
    }

    public boolean onConsoleMessageSuper(XWalkViewBridge view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
        boolean ret;
        ret = super.onConsoleMessage(view, message, lineNumber, sourceId, messageType);
        
        return ret;
    }

    private ReflectMethod onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod = new ReflectMethod(null, "onConsoleMessage");

    @Override
    public void onReceivedTitle(XWalkViewInternal view, String title) {
        if ((view instanceof XWalkViewBridge)) {
            onReceivedTitle((XWalkViewBridge) view, title);
        } else {
            super.onReceivedTitle(view, title);
        }
    }

    public void onReceivedTitle(XWalkViewBridge view, String title) {
        if (onReceivedTitleXWalkViewInternalStringMethod == null || onReceivedTitleXWalkViewInternalStringMethod.isNull()) {
            onReceivedTitleSuper(view, title);
        } else {
            onReceivedTitleXWalkViewInternalStringMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), title);
        }
    }

    public void onReceivedTitleSuper(XWalkViewBridge view, String title) {
        super.onReceivedTitle(view, title);
    }

    private ReflectMethod onReceivedTitleXWalkViewInternalStringMethod = new ReflectMethod(null, "onReceivedTitle");

    @Override
    public void onPageLoadStarted(XWalkViewInternal view, String url) {
        if ((view instanceof XWalkViewBridge)) {
            onPageLoadStarted((XWalkViewBridge) view, url);
        } else {
            super.onPageLoadStarted(view, url);
        }
    }

    public void onPageLoadStarted(XWalkViewBridge view, String url) {
        if (onPageLoadStartedXWalkViewInternalStringMethod == null || onPageLoadStartedXWalkViewInternalStringMethod.isNull()) {
            onPageLoadStartedSuper(view, url);
        } else {
            onPageLoadStartedXWalkViewInternalStringMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url);
        }
    }

    public void onPageLoadStartedSuper(XWalkViewBridge view, String url) {
        super.onPageLoadStarted(view, url);
    }

    private ReflectMethod onPageLoadStartedXWalkViewInternalStringMethod = new ReflectMethod(null, "onPageLoadStarted");

    @Override
    public void onPageLoadStopped(XWalkViewInternal view, String url, LoadStatusInternal status) {
        if ((view instanceof XWalkViewBridge)) {
            onPageLoadStopped((XWalkViewBridge) view, url, status);
        } else {
            super.onPageLoadStopped(view, url, status);
        }
    }

    public void onPageLoadStopped(XWalkViewBridge view, String url, LoadStatusInternal status) {
        if (onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod == null || onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod.isNull()) {
            onPageLoadStoppedSuper(view, url, status);
        } else {
            onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url, ConvertLoadStatusInternal(status));
        }
    }

    public void onPageLoadStoppedSuper(XWalkViewBridge view, String url, LoadStatusInternal status) {
        super.onPageLoadStopped(view, url, status);
    }

    private ReflectMethod onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod = new ReflectMethod(null, "onPageLoadStopped");

    @Override
    public boolean onJsAlert(XWalkViewInternal view, String url, String message, XWalkJavascriptResultInternal result) {
        if ((view instanceof XWalkViewBridge)) {
            return onJsAlert((XWalkViewBridge) view, url, message, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)));
        } else {
            return super.onJsAlert(view, url, message, result);
        }
    }

    public boolean onJsAlert(XWalkViewBridge view, String url, String message, XWalkJavascriptResultHandlerBridge result) {
        if (onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod == null || onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.isNull()) {
            return onJsAlertSuper(view, url, message, result);
        } else {
            return (Boolean)onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url, message, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)).getWrapper());
        }
    }

    public boolean onJsAlertSuper(XWalkViewBridge view, String url, String message, XWalkJavascriptResultHandlerBridge result) {
        boolean ret;
        ret = super.onJsAlert(view, url, message, result);
        
        return ret;
    }

    private ReflectMethod onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJsAlert");

    @Override
    public boolean onJsConfirm(XWalkViewInternal view, String url, String message, XWalkJavascriptResultInternal result) {
        if ((view instanceof XWalkViewBridge)) {
            return onJsConfirm((XWalkViewBridge) view, url, message, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)));
        } else {
            return super.onJsConfirm(view, url, message, result);
        }
    }

    public boolean onJsConfirm(XWalkViewBridge view, String url, String message, XWalkJavascriptResultHandlerBridge result) {
        if (onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod == null || onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.isNull()) {
            return onJsConfirmSuper(view, url, message, result);
        } else {
            return (Boolean)onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url, message, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)).getWrapper());
        }
    }

    public boolean onJsConfirmSuper(XWalkViewBridge view, String url, String message, XWalkJavascriptResultHandlerBridge result) {
        boolean ret;
        ret = super.onJsConfirm(view, url, message, result);
        
        return ret;
    }

    private ReflectMethod onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJsConfirm");

    @Override
    public boolean onJsPrompt(XWalkViewInternal view, String url, String message, String defaultValue, XWalkJavascriptResultInternal result) {
        if ((view instanceof XWalkViewBridge)) {
            return onJsPrompt((XWalkViewBridge) view, url, message, defaultValue, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)));
        } else {
            return super.onJsPrompt(view, url, message, defaultValue, result);
        }
    }

    public boolean onJsPrompt(XWalkViewBridge view, String url, String message, String defaultValue, XWalkJavascriptResultHandlerBridge result) {
        if (onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod == null || onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod.isNull()) {
            return onJsPromptSuper(view, url, message, defaultValue, result);
        } else {
            return (Boolean)onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod.invoke((view instanceof XWalkViewBridge ? ((XWalkViewBridge) view ) : null).getWrapper(), url, message, defaultValue, (result instanceof XWalkJavascriptResultHandlerBridge ? ((XWalkJavascriptResultHandlerBridge) result ) : new XWalkJavascriptResultHandlerBridge((XWalkJavascriptResultHandlerInternal) result)).getWrapper());
        }
    }

    public boolean onJsPromptSuper(XWalkViewBridge view, String url, String message, String defaultValue, XWalkJavascriptResultHandlerBridge result) {
        boolean ret;
        ret = super.onJsPrompt(view, url, message, defaultValue, result);
        
        return ret;
    }

    private ReflectMethod onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJsPrompt");

    @Override
    public void onShowCustomView(View view, CustomViewCallbackInternal callback) {
        onShowCustomView(view, (callback instanceof CustomViewCallbackHandlerBridge ? ((CustomViewCallbackHandlerBridge) callback ) : new CustomViewCallbackHandlerBridge((CustomViewCallbackHandlerInternal) callback)));
    }

    public void onShowCustomView(View view, CustomViewCallbackHandlerBridge callback) {
        if (onShowCustomViewViewCustomViewCallbackInternalMethod == null || onShowCustomViewViewCustomViewCallbackInternalMethod.isNull()) {
            onShowCustomViewSuper(view, callback);
        } else {
            onShowCustomViewViewCustomViewCallbackInternalMethod.invoke(view, (callback instanceof CustomViewCallbackHandlerBridge ? ((CustomViewCallbackHandlerBridge) callback ) : new CustomViewCallbackHandlerBridge((CustomViewCallbackHandlerInternal) callback)).getWrapper());
        }
    }

    public void onShowCustomViewSuper(View view, CustomViewCallbackHandlerBridge callback) {
        super.onShowCustomView(view, callback);
    }

    private ReflectMethod onShowCustomViewViewCustomViewCallbackInternalMethod = new ReflectMethod(null, "onShowCustomView");

    @Override
    public void onShowCustomView(View view, int requestedOrientation, CustomViewCallbackInternal callback) {
        onShowCustomView(view, requestedOrientation, (callback instanceof CustomViewCallbackHandlerBridge ? ((CustomViewCallbackHandlerBridge) callback ) : new CustomViewCallbackHandlerBridge((CustomViewCallbackHandlerInternal) callback)));
    }

    public void onShowCustomView(View view, int requestedOrientation, CustomViewCallbackHandlerBridge callback) {
        if (onShowCustomViewViewintCustomViewCallbackInternalMethod == null || onShowCustomViewViewintCustomViewCallbackInternalMethod.isNull()) {
            onShowCustomViewSuper(view, requestedOrientation, callback);
        } else {
            onShowCustomViewViewintCustomViewCallbackInternalMethod.invoke(view, requestedOrientation, (callback instanceof CustomViewCallbackHandlerBridge ? ((CustomViewCallbackHandlerBridge) callback ) : new CustomViewCallbackHandlerBridge((CustomViewCallbackHandlerInternal) callback)).getWrapper());
        }
    }

    public void onShowCustomViewSuper(View view, int requestedOrientation, CustomViewCallbackHandlerBridge callback) {
        super.onShowCustomView(view, requestedOrientation, callback);
    }

    private ReflectMethod onShowCustomViewViewintCustomViewCallbackInternalMethod = new ReflectMethod(null, "onShowCustomView");

    @Override
    public void onHideCustomView() {
        if (onHideCustomViewMethod == null || onHideCustomViewMethod.isNull()) {
            onHideCustomViewSuper();
        } else {
            onHideCustomViewMethod.invoke();
        }
    }

    public void onHideCustomViewSuper() {
        super.onHideCustomView();
    }

    private ReflectMethod onHideCustomViewMethod = new ReflectMethod(null, "onHideCustomView");


    void reflectionInit() {
        coreBridge = XWalkCoreBridge.getInstance();
        if (coreBridge == null) return;

        enumJavascriptMessageTypeClassValueOfMethod.init(null,
                coreBridge.getWrapperClass("XWalkUIClient$JavascriptMessageType"), "valueOf", String.class);
        enumConsoleMessageTypeClassValueOfMethod.init(null,
                coreBridge.getWrapperClass("XWalkUIClient$ConsoleMessageType"), "valueOf", String.class);
        enumInitiateByClassValueOfMethod.init(null,
                coreBridge.getWrapperClass("XWalkUIClient$InitiateBy"), "valueOf", String.class);
        enumLoadStatusClassValueOfMethod.init(null,
                coreBridge.getWrapperClass("XWalkUIClient$LoadStatus"), "valueOf", String.class);

        onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod.init(wrapper, null,
                "onCreateWindowRequested", coreBridge.getWrapperClass("XWalkView"), coreBridge.getWrapperClass("XWalkUIClient$InitiateBy"), ValueCallback.class);
        onIconAvailableXWalkViewInternalStringMessageMethod.init(wrapper, null,
                "onIconAvailable", coreBridge.getWrapperClass("XWalkView"), String.class, Message.class);
        onReceivedIconXWalkViewInternalStringBitmapMethod.init(wrapper, null,
                "onReceivedIcon", coreBridge.getWrapperClass("XWalkView"), String.class, Bitmap.class);
        onRequestFocusXWalkViewInternalMethod.init(wrapper, null,
                "onRequestFocus", coreBridge.getWrapperClass("XWalkView"));
        onJavascriptCloseWindowXWalkViewInternalMethod.init(wrapper, null,
                "onJavascriptCloseWindow", coreBridge.getWrapperClass("XWalkView"));
        onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod.init(wrapper, null,
                "onJavascriptModalDialog", coreBridge.getWrapperClass("XWalkView"), coreBridge.getWrapperClass("XWalkUIClient$JavascriptMessageType"), String.class, String.class, String.class, coreBridge.getWrapperClass("XWalkJavascriptResult"));
        onFullscreenToggledXWalkViewInternalbooleanMethod.init(wrapper, null,
                "onFullscreenToggled", coreBridge.getWrapperClass("XWalkView"), boolean.class);
        openFileChooserXWalkViewInternalValueCallbackStringStringMethod.init(wrapper, null,
                "openFileChooser", coreBridge.getWrapperClass("XWalkView"), ValueCallback.class, String.class, String.class);
        onScaleChangedXWalkViewInternalfloatfloatMethod.init(wrapper, null,
                "onScaleChanged", coreBridge.getWrapperClass("XWalkView"), float.class, float.class);
        shouldOverrideKeyEventXWalkViewInternalKeyEventMethod.init(wrapper, null,
                "shouldOverrideKeyEvent", coreBridge.getWrapperClass("XWalkView"), KeyEvent.class);
        onUnhandledKeyEventXWalkViewInternalKeyEventMethod.init(wrapper, null,
                "onUnhandledKeyEvent", coreBridge.getWrapperClass("XWalkView"), KeyEvent.class);
        onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod.init(wrapper, null,
                "onConsoleMessage", coreBridge.getWrapperClass("XWalkView"), String.class, int.class, String.class, coreBridge.getWrapperClass("XWalkUIClient$ConsoleMessageType"));
        onReceivedTitleXWalkViewInternalStringMethod.init(wrapper, null,
                "onReceivedTitle", coreBridge.getWrapperClass("XWalkView"), String.class);
        onPageLoadStartedXWalkViewInternalStringMethod.init(wrapper, null,
                "onPageLoadStarted", coreBridge.getWrapperClass("XWalkView"), String.class);
        onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod.init(wrapper, null,
                "onPageLoadStopped", coreBridge.getWrapperClass("XWalkView"), String.class, coreBridge.getWrapperClass("XWalkUIClient$LoadStatus"));
        onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.init(wrapper, null,
                "onJsAlert", coreBridge.getWrapperClass("XWalkView"), String.class, String.class, coreBridge.getWrapperClass("XWalkJavascriptResult"));
        onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.init(wrapper, null,
                "onJsConfirm", coreBridge.getWrapperClass("XWalkView"), String.class, String.class, coreBridge.getWrapperClass("XWalkJavascriptResult"));
        onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod.init(wrapper, null,
                "onJsPrompt", coreBridge.getWrapperClass("XWalkView"), String.class, String.class, String.class, coreBridge.getWrapperClass("XWalkJavascriptResult"));
        onShowCustomViewViewCustomViewCallbackInternalMethod.init(wrapper, null,
                "onShowCustomView", View.class, coreBridge.getWrapperClass("CustomViewCallback"));
        onShowCustomViewViewintCustomViewCallbackInternalMethod.init(wrapper, null,
                "onShowCustomView", View.class, int.class, coreBridge.getWrapperClass("CustomViewCallback"));
        onHideCustomViewMethod.init(wrapper, null,
                "onHideCustomView");
    }
}
